package com.yanqu.road.server.logic.activity.condition.chefduel;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.server.logic.activity.relation.condition.arg.ChefDuel1RankArg;
import com.yanqu.road.server.logic.activity.relation.condition.arg.ChefDuel1UnlimitedRankArg;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

public class ChefDuel1UnlimitedRankCondition extends BaseNewRankActivityCondition {

    public ChefDuel1UnlimitedRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ChefDuelPhase1UnlimitedRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ChefDuelPhase1UnlimitedRank.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return false;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        if (StringUtils.isNullOrEmpty(getParam())){
            setParam("0");
        }
        ChefDuel1UnlimitedRankArg arg = (ChefDuel1UnlimitedRankArg) object;
        if (null != arg) {
            //值是顾客数
            setValue(BigInteger.valueOf(arg.getGuest()));
            //参数是银币
            setParam(String.valueOf(arg.getCoin()));
            //重新生成排行榜
            rankChange();
        }
    }

}
